<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author  Nguyen Xuan Hung
 * @email   hungnguyen@vietnambiz.com
 * @date    10.02.2011
 */
  
class User_model extends MY_Model {
    
    function __construct()
    {
        parent::__construct();
        
        $this->_table      = 'users';
        $this->primary_key = 'user_id';
    }
    
    function get_group_list()
    {
        return $this->db->order_by('group_name ASC')->get('user_groups')->result_array();
    }
    
    function check_exist($username = '')
    {
        $u = $this->get_by('username', $username);
        
        if(isset($u->user_id) && $u->user_id > 0) return true;
        else return false;
    }
        
    function group_name($group_id = null)
    {
    	$r = $this->db->where('group_id', $group_id)->limit(1)->get('user_groups')->row();
    	return isset($r->group_name) ? $r->group_name : 'Not exist';
    }
}
